package com.spic.business.plan.exercisePlan.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.business.plan.exercisePlan.domain.PlanExercisePlan;
import com.spic.business.plan.exercisePlan.service.IPlanExercisePlanService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * 应急演练计划Controller
 * 
 * @author spic
 * @date 2021-11-09
 */
@RestController
@RequestMapping("/plan/exercisePlan")
public class PlanExercisePlanController extends BaseController
{
    @Autowired
    private IPlanExercisePlanService planExercisePlanService;

    /**
     * 查询应急演练计划列表
     */
    @PreAuthorize(hasPermi = "business/plan:exercisePlan:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanExercisePlan planExercisePlan)
    {
        startPage();
        List<PlanExercisePlan> list = planExercisePlanService.selectPlanExercisePlanList(planExercisePlan);
        return getDataTable(list);
    }

    /**
     * 导出应急演练计划列表
     */
    @PreAuthorize(hasPermi = "business/plan:exercisePlan:export")
    @Log(title = "应急演练计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanExercisePlan planExercisePlan) throws IOException
    {
        List<PlanExercisePlan> list = planExercisePlanService.selectPlanExercisePlanList(planExercisePlan);
        ExcelUtil<PlanExercisePlan> util = new ExcelUtil<PlanExercisePlan>(PlanExercisePlan.class);
        util.exportExcel(response, list, "应急演练计划数据");
    }

    /**
     * 获取应急演练计划详细信息
     */
    @PreAuthorize(hasPermi = "business/plan:exercisePlan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(planExercisePlanService.selectPlanExercisePlanById(id));
    }

    /**
     * 新增应急演练计划
     */
    @PreAuthorize(hasPermi = "business/plan:exercisePlan:add")
    @Log(title = "应急演练计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanExercisePlan planExercisePlan)
    {
        return AjaxResult.success(planExercisePlanService.insertPlanExercisePlan(planExercisePlan));
    }

    /**
     * 修改应急演练计划
     */
    @PreAuthorize(hasPermi = "business/plan:exercisePlan:edit")
    @Log(title = "应急演练计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanExercisePlan planExercisePlan)
    {
        return toAjax(planExercisePlanService.updatePlanExercisePlan(planExercisePlan));
    }

    /**
     * 删除应急演练计划
     */
    @PreAuthorize(hasPermi = "business/plan:exercisePlan:remove")
    @Log(title = "应急演练计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(planExercisePlanService.deletePlanExercisePlanByIds(ids));
    }
}
